<?php

class ReplyAction extends Action{
		/*加减分*/
		public function checkVote2(){
			$id = (int)$_POST['id'];
			$kind = (int)$_POST['kind'];
			if(in_array($id,explode('%',$_COOKIE['vote2Id']))){
				echo '-1-';
			}else{
				if($kind<0){
					M('News')->where("id = $id")->setInc('no');
					$vote = explode(',',$_COOKIE['vote2Id']);
					$vote[] = $id;
					$vote2Id = implode('%',$vote);
					setcookie('vote2Id',$vote2Id,$_SERVER['REQUEST_TIME']+100000000);
					echo '-1';
				}else{
					M('News')->where("id = $id")->setInc('yes');
					$vote = explode(',',$_COOKIE['vote2Id']);
					$vote[] = $id;
					$vote2Id = implode('%',$vote);
					setcookie('vote2Id',$vote2Id,$_SERVER['REQUEST_TIME']+100000000);
					echo '+1';
				}
			}
		}
		
		public function checkReply2(){
			if($_COOKIE['com_time']+C('com_time') > time()){
				exit('44');
			}
			setcookie("com_time",time());
			$reply = C('reply');
			if(empty($_SESSION['uid']) && !$reply){
				$_POST['arid'] = '1';
				$_POST['arname'] = '匿名';
				$_POST['face']='noface.png';
			}else{
				$_POST['arid'] = empty($_POST['anonymous']) ? $_SESSION['uid'] : '1';
				$_POST['arname'] = empty($_POST['anonymous']) ? $_SESSION['uname'] : '匿名';
				$_POST['face']=$_SESSION['face'];
			}
			$_POST['arcontent'] =  htmlspecialchars($_POST['arcontent']);
			$_POST['artime'] = $_SERVER['REQUEST_TIME'];
			$_POST['pid'] = (int)$_POST['pid'];
			$_POST['ip'] = ip2long(get_client_ip());
			$_POST['state'] = '1';
			if(empty($_POST['arcontent'])){
				echo '0';
			}else if(M('Reply')->add($_POST)){
				$uid = $_POST['arid'];
				M('User')->where("uid = $uid")->setInc('comments');
				M('User')->where("uid = $uid")->setInc('score',C('com_score'));
				$id = $_POST['pid'];
				M('News')->where("id = $id")->setInc('reply');
				
			}else{
				echo '-1';
			}
		}
		public function checkReply(){
			
			if($_COOKIE['com_time']+C('com_time') > time()){
				$this->error('不能频繁灌水');
			}	
			setcookie("com_time",time());
			$reply = C('reply');
			if(empty($_SESSION['uid']) && !$reply){
				$_POST['arid'] = '1';
				$_POST['arname'] = '匿名'; 
			}else{
				$_POST['arid'] = empty($_POST['anonymous']) ? $_SESSION['uid'] : '1';
				$_POST['arname'] = empty($_POST['anonymous']) ? $_SESSION['uname'] : '匿名';
			}
			$_POST['arcontent'] =  htmlspecialchars($_POST['arcontent']);
			$_POST['artime'] = $_SERVER['REQUEST_TIME'];
			$_POST['pid'] = (int)$_POST['pid'];
			$_POST['ip'] = ip2long(get_client_ip());
			$_POST['state'] = '1';
			if(empty($_POST['arcontent'])) $this->error('回复就得有内容嘛!');
			if(M('Reply')->add($_POST)){
				$uid=$_SESSION['uid'];
				$id = $_POST['pid'];
				M('User')->where("uid = $uid")->setInc('comments');
				M('User')->where("uid = $uid")->setInc('score',C('com_score'));
				M('News')->where("id = $id")->setInc('reply');
				$this->success('发表成功!'.C('diy_field_name').'+'.C('com_score'));
			}else{
				$this->error('发表失败!');
			}
		}
	}

?>